package com.cuit.xsc.weishare.model;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.cuit.xsc.weishare.util.ConfigUtil;
import com.cuit.xsc.weishare.util.LogUtil;

public class DirectMessage implements Serializable
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int RECV = 1;
	public static final int SEND = 2;
	

	private String id;
	private String head;
	private long time;
	private String text;
	private String nick;
	private String name;
	private boolean isVerified;
	private int type;
	private String toname;
	private String tonick;
	private String tohead;
	private boolean toIsVip;
	
	
	
    public DirectMessage(int type)
	{
    	this.type = type;
	}
	
	public DirectMessage(int type, String json) throws JSONException
	{
		this(type);
		JSONObject jsonObject = new JSONObject(json);
        constructQQJson(jsonObject);
	}
	
	public DirectMessage(int type, JSONObject jsonObject)
	{
		this(type);
		constructQQJson(jsonObject);
	}
	
	
	
	private void constructQQJson(JSONObject json)
	{
		try
		{
			//LogUtil.e(this, "json="+json.toString());	
			id = json.getString("id");
			head = json.getString("head")+"/"+ConfigUtil.QQ_HEAD_IMAGE_SIZE;
			nick = json.getString("nick");
			name = json.getString("name");
			int verified = json.getInt("isvip");
			if (verified == 0)
			{
				isVerified = false;
			}
			else if(verified == 1)
			{
				isVerified = true;
			}
			time = json.getLong("timestamp");
			text = json.getString("text");	
			toname = json.getString("toname");
			tonick = json.getString("tonick");
			tohead = json.getString("tohead");
			if (tohead != null && !"".equals(tohead))
			{
				tohead += "/"+ConfigUtil.QQ_HEAD_IMAGE_SIZE;
			}
			
			int toisvip = json.getInt("toisvip");
			if (toisvip == 0)
			{
				toIsVip = false;
			}
			else if(toisvip == 1)
			{
				toIsVip = true;
			}
			
		}
		catch (JSONException e)
		{
			e.printStackTrace();
		}
		
	}
	
	
	public String getId()
	{
		return id;
	}
	public void setId(String id)
	{
		this.id = id;
	}
	public String getHead()
	{
		return head;
	}
	public void setHead(String head)
	{
		this.head = head;
	}
	public long getTime()
	{
		return time;
	}
	public void setTime(long time)
	{
		this.time = time;
	}
	public String getText()
	{
		return text;
	}
	public void setText(String text)
	{
		this.text = text;
	}
	public String getNick()
	{
		return nick;
	}
	public void setNick(String nick)
	{
		this.nick = nick;
	}
	public boolean isVerified()
	{
		return isVerified;
	}
	public void setVerified(boolean isVerified)
	{
		this.isVerified = isVerified;
	}
	public int getType()
	{
		return type;
	}
	public void setType(int type)
	{
		this.type = type;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getToname()
	{
		return toname;
	}

	public void setToname(String toname)
	{
		this.toname = toname;
	}

	public String getTonick()
	{
		return tonick;
	}

	public void setTonick(String tonick)
	{
		this.tonick = tonick;
	}

	public String getTohead()
	{
		return tohead;
	}

	public void setTohead(String tohead)
	{
		this.tohead = tohead;
	}

	public boolean isToIsVip()
	{
		return toIsVip;
	}

	public void setToIsVip(boolean toIsVip)
	{
		this.toIsVip = toIsVip;
	}	
	
	

}
